package com.ui.design.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;

/**
 * SharedPreferences存储数据方式工具类
 * Created by huangweifeng on 2016/3/15.
 */
public class SharePrefenceUtil {


    public final static String SETTING = "UIDesign";

    public static void putValue(Context context, String key, int value) {
        Editor sp = context.getSharedPreferences(SETTING, Context.MODE_PRIVATE).edit();
        sp.putInt(key, value);
        sp.apply();
    }

    public static void putValue(Context context, String key, boolean value) {
        Editor sp = context.getSharedPreferences(SETTING, Context.MODE_PRIVATE).edit();
        sp.putBoolean(key, value);
        sp.apply();
    }

    public static void putValue(Context context, String key, String value) {
            Editor sp = context.getSharedPreferences(SETTING, Context.MODE_PRIVATE).edit();
            sp.putString(key, value);
            sp.apply();
    }

    public static int getValue(Context context, String key, int defValue) {
        SharedPreferences sp = context.getSharedPreferences(SETTING, Context.MODE_PRIVATE);
        int value = sp.getInt(key, defValue);
        return value;
    }

    public static boolean getValue(Context context, String key, boolean defValue) {
        SharedPreferences sp = context.getSharedPreferences(SETTING, Context.MODE_PRIVATE);
        boolean value = sp.getBoolean(key, defValue);
        return value;
    }

    public static String getValue(Context context, String key, String defValue) {
            SharedPreferences sp = context.getSharedPreferences(SETTING, Context.MODE_PRIVATE);
            String value = sp.getString(key, defValue);
            return value;
    }

    public static void remove(String key, Context context) {
        PreferenceManager.getDefaultSharedPreferences(context).edit().remove(key).apply();
    }
}
